package communication;


import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;


public class VideoStreamReceiverThread extends Thread
{
   private DatagramSocket socket;

   public VideoStreamReceiverThread()
   {
      this.setDaemon(true);
   }

   @Override
   public void run()
   {
      int size = 0;
      System.out
            .println("======================= Viedeo Stream Receiver gestartet ========================");
      while (true)
      {

         byte[] recievedData = new byte[35535];
         DatagramPacket packet = new DatagramPacket(recievedData,
               recievedData.length);
         try
         {
            socket.receive(packet);

            size = recievedData[14] & 0xFF;
            size = (size << 8) & recievedData[15];

            byte[] jpgFrame = new byte[size];
            System.arraycopy(recievedData, 16, jpgFrame, 0, jpgFrame.length);
 //           Wirc.getInstance().setJpegFrame(jpgFrame);

         } catch (IOException e)
         {
            e.printStackTrace();
         }
      }
   }
}
